package com.easy.controller;


import com.easy.util.ImageUtil;
import com.easy.util.Result;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.io.InputStream;

@RestController
@RequestMapping("/upload")
public class UploadController {
    @RequestMapping("/file")
    public Result upload(MultipartFile file){
        try{
            InputStream is = file.getInputStream();
            String filename = file.getOriginalFilename();
            String newFileName = ImageUtil.upload(is, filename);

            return Result.success(newFileName);
        }catch (IOException e){
            return Result.fail(500,"图片上传失败");
        }
    }
}